<?php
/**
 * Created by PhpStorm.
 * User: hexvliang
 * Date: 2015/10/20
 * Time: 18:49
 */

namespace Common\Common;


use Org\Sentry\Sentry;

class getSentry
{
    /**
     * 获取日志服务器客户端
     * @return \Raven_Client
     */
    private static function get()
    {
        $dns=C("sentry_dns");
        $option=C("sentry_option");

        return Sentry::getInstance($dns,$option);
    }

    /**
     * 捕获一个异常
     * @param $exception
     * @param null $culprit_or_options
     * @param null $logger
     * @param null $vars
     */
    public static function sentryException($exception, $culprit_or_options=null, $logger=null, $vars=null)
    {
        if(C('sentry_on')){
            $client=self::get();
            $client->captureException($exception, $culprit_or_options, $logger, $vars);
        }
    }

    /**
     * 记录一个消息
     * @param $message
     * @param array $params
     * @param string $level_or_options  'debug'  'info'  'warning' 'error' 'fatal' 也可以是数组array('level'=>'前面定义的字符串','tags'=>array(),'extra'=>array())
     * @param bool|false $stack
     * @param null $vars
     */
    public static function sentryMessage($message, $level_or_options=null,$params=array(),$stack=false, $vars = null)
    {
        if(C('sentry_on')){
            $client=self::get();
            $client->captureMessage($message,$params, $level_or_options,
                $stack, $vars );
        }
    }

}